% %% standard deviation
% tempData=readfid('./data/fid_ss_test', 1);
% figHandle=figure('Position', [70, 30, 1200, 900]);
% subplot(4,1,1, 'Position', [0.05, 3.9/5, 0.9, 1/5]);
% plot(real(tempData));
% 
% tempStd1 = std(tempData, 1);
% 
% tempData=readfid('./data/fid_ss_test', 2);
% subplot(4,1,2, 'Position', [0.05, 2.8/5, 0.9, 1/5]);
% plot(real(tempData));
% 
% tempStd2 = std(tempData); 
% 
% tempData=readfid('./data/fid_ss_test', 3);
% subplot(4,1,3, 'Position', [0.05, 1.7/5, 0.9, 1/5]);
% plot(real(tempData));
% 
% tempStd3 = std(tempData); 
% 
% tempData=readfid('./data/fid_ss_test', 4);
% subplot(4,1,4, 'Position', [0.05, 0.6/5, 0.9, 1/5]);
% plot(real(tempData));
% 
% tempStd4 = std(tempData);
% 
% fp=get(figHandle, 'Position');
% 
% textDisp1 = uicontrol('Style', 'text', 'Position', [1, 1, fp(3), fp(4)/11]);
% blank1 = sprintf('\n');
% strEmpty = sprintf('Standard deviation of plot1 is %f\n', tempStd1);
% str2 = sprintf('Standard deviation of plot2 is %f\n', tempStd2);
% str3 = sprintf('Standard deviation of plot3 is %f\n', tempStd3);
% str4 = sprintf('Standard deviation of plot4 is %f\n', tempStd4);
% 
% TotalStr = [blank1 strEmpty str2 str3 str4];
% set(textDisp1, 'String', TotalStr);
% 
% figID2 = figure();
% fp2=get(figID2, 'Position');
% tempData=readfid('./data/fid_empty5', 1);
% plot(real(tempData));
% stdEmpty = std(tempData, 1);
% textDisp2 = uicontrol('Style', 'text', 'Position', [0, 0, fp2(3)/2, fp2(4)/10]);
% blank1 = sprintf('\n');
% strEmpty = sprintf('Standard deviation is %f\n', stdEmpty);
% set(textDisp2, 'String', [blank1 strEmpty]);
% 
% figID3 = figure();
% fp2=get(figID3, 'Position');
% tempData=readfid('./data/fid', 1);
% plot(real(tempData));
% stdEmpty = std(tempData,1);
% textDisp3 = uicontrol('Style', 'text', 'Position', [0, 0, fp2(3)/2, fp2(4)/10]);
% blank1 = sprintf('\n');
% strEmpty = sprintf('Standard deviation is %f\n', stdEmpty);
% set(textDisp3, 'String', [blank1 strEmpty]);
% 
% %% fft of noise
% figure(114)
% spectrumEmpty = fft(tempData);
% spectrumEmpty = circshift(spectrumEmpty, length(spectrumEmpty)/2);
% plot(real(spectrumEmpty));
% 
% clear;

% %% Measurement of Noise
% 
% figID5=figure(115);
% n=10;
% tempData1 = readfid('./data/fid_ss_test', 1);
% tempData2 = readfid('./data/fid_ss_test', 4*n+1);
% 
% subData = tempData1 - tempData2;
% stdSubData = std(subData);
% stdData = std(tempData2);
% 
% 
% fp=get(figID5, 'Position');
% textArea1 = uicontrol('Style', 'text', 'Position', [0, 0, fp(3), fp(4)/15]);
% subplot(2,1,1);
% plot(subData);
% 
% tempData3 = readfid('./data/fid_empty3', 1);
% stdNoise = std(tempData3);
% 
% subplot(2,1,2);
% plot(tempData3);
% 
% str1=sprintf('subNoise : %f, emptyNoise : %f\n', stdSubData, stdNoise);
% str2=sprintf('signal noise : %f \n', stdData);
% str3=sprintf('SNR : %f', stdData/stdSubData);
% set(textArea1, 'String', [str1 str2 str3]);

% %% ploting the SNR
% reference=2;
% channel=1;
% 
% tempData3 = readfid('./data/fid_empty3', 4);
% stdNoise = std(tempData3);
% 
% for n=1:1:49
% % tempData1 = readfid('./data/fid_ss_test', channel+(reference-1)*4);
% tempData2 = readfid('./data/fid_ss_test', 4*n+channel);
% 
% 
% 
% % subtractData = tempData1 - tempData2;
% % stdSubtractData = std(subtractData);
% stdData = std(tempData2);
% SNR(n) = stdData/stdNoise;
% end
% 
% figure;
% plot(SNR);

%% ploting subtraction
channel = 4;
reference = 1;
nblocks = 50;
index1 = 1;


tempData1 = readfid('./data/fid_ss_test', channel+(reference-1)*4);

figure(1);
for indx=1:1:nblocks
    if (1 == mod(indx, 10)) & (indx~=1) 
        index1 = index1 + 1;
        figure(index1);
    end
    
    tempData2 = readfid('./data/fid_ss_test', 4*(indx-1)+channel);
    tempData = tempData2-tempData1;
    plotOrder=mod(indx, 10);
    if plotOrder == 0
        plotOrder = 10;
    end
    
    meanData(indx) = mean(tempData, 1);
    stdData(indx) = std(tempData, 1);
    coreff(indx) = corr(tempData1, tempData2);
    stdSpectrum(indx) = std(tempData2);
        
    subplot(10, 1, plotOrder);    
    plot(tempData);
    ylim([-2, 2]);
    
    
end
chStd = mean(stdSpectrum, 2)

figure(6)
plot(meanData);
title('mean of subtraction');
figure(7)
plot(stdData(2:50));
title('Standard deviation of subtraction');
figure(8)
plot(coreff(2:50));
title('Correlation of two spectra');
figure(9)
plot(stdSpectrum);
title('Standard deviation of Spectra');





